﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for DaiLyCtr
/// </summary>
public class DaiLyCtr
{
	public DaiLyCtr()
	{

	}

    public DataTable layDaiLy()
    {
        try
        {
            string sql = "select * from DaiLy ";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    public EDaiLy layDaiLy(int MaDaiLy)
    {
        try
        {
            DataTable tableDaiLy = DataProvider.GetData("Select * from DaiLy Where MaDaiLy=@MaDaiLy", "@MaDaiLy", MaDaiLy);
            EDaiLy DaiLy = new EDaiLy();
            DaiLy.MaDaiLy = Int32.Parse(tableDaiLy.Rows[0]["MaDaiLy"].ToString());
            DaiLy.TenDaiLy = tableDaiLy.Rows[0]["TenDaiLy"].ToString();
            DaiLy.Noidung = tableDaiLy.Rows[0]["Noidung"].ToString();
            DaiLy.MaNV = Int32.Parse(tableDaiLy.Rows[0]["Link"].ToString());
           
            return DaiLy;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public bool InsertDaiLy(EDaiLy DaiLy)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO DaiLy VAlUES(@MaDaiLy,@TenDaiLy,@HinhAnh,@Noidung,@MaNV)",
                 "@MaDaiLy", DaiLy.MaDaiLy,"@TenDaiLy",DaiLy.TenDaiLy,"@HinhAnh",DaiLy.HinhAnh, "@Noidung", DaiLy.Noidung,"@MaNV",DaiLy.MaNV);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public bool DeleteDaiLy(int MaDaiLy)
    {
        try
        {
            DataProvider.ExecuteNonQuery("DELETE FROM DaiLy WHERE MaDaiLy=@MaDaiLy", "@MaDaiLy", MaDaiLy);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public bool UpdateDaiLy(EDaiLy DaiLy)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update DaiLy set TenDaiLy=@TenDaiLy,HinhAnh=@HinhAnh,Noidung=@Noidung,MaNV=@MaNV WHERE MaDaiLy=@MaDaiLy", "@MaDaiLy", DaiLy.MaDaiLy,"@TenDaiLy",DaiLy.TenDaiLy, "@Noidung", DaiLy.Noidung, "@MaNV", DaiLy.MaNV,"@HinhAnh",DaiLy.HinhAnh);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    //Hanh
    public bool UpdateDaiLyH(EDaiLy DaiLy)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update DaiLy set TenDaiLy=@TenDaiLy,HinhAnh=@HinhAnh,Noidung=@Noidung WHERE MaDaiLy=@MaDaiLy", "@MaDaiLy", DaiLy.MaDaiLy, "@Noidung", DaiLy.Noidung, "@TenDaiLy", DaiLy.TenDaiLy, "@HinhAnh", DaiLy.HinhAnh);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool InsertDaiLyH(EDaiLy DaiLy)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO DaiLy VAlUES(@TenDaiLy,@HinhAnh,@Noidung,@MaNV)",
                 "@TenDaiLy", DaiLy.TenDaiLy,"@HinhAnh",DaiLy.HinhAnh,"@Noidung", DaiLy.Noidung, "@MaNV", DaiLy.MaNV);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}